package com.casic.modules.sys.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.casic.common.utils.R;
import com.casic.common.base.entity.PageEntity;
import com.casic.common.validator.ValidatorUtils;
import com.casic.common.validator.group.AddGroup;
import com.casic.modules.sys.entity.SysEnclosureEntity;
import com.casic.modules.sys.service.SysEnclosureService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.casic.modules.sys.entity.SysAppversionEntity;
import com.casic.modules.sys.service.SysAppversionService;


/**
 * 
 * 
 * @author 颜金星
 * @email 123456789@qq.com
 * @date 2017-12-19 16:13:46
 */
@RestController
@RequestMapping("sysappversion")
public class SysAppversionController {
	@Autowired
	private SysAppversionService sysAppversionService;

	@Autowired
	private SysEnclosureService sysEnclosureService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
        PageEntity<SysAppversionEntity> page=sysAppversionService.findPage(params);
		return R.ok().put("page", page);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") String id){
		SysAppversionEntity sysAppversion = sysAppversionService.findById(id);
		SysEnclosureEntity sysEnclosureEntity=sysEnclosureService.findById(sysAppversion.getApkPath());
		Map<String,Object> data=new HashMap<>();
		data.put("sysAppversion",sysAppversion);
		data.put("sysEnclosureEntity",sysEnclosureEntity);
		return R.ok(data);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody SysAppversionEntity sysAppversion){
		sysAppversion.setUploadDate(new Date());
		ValidatorUtils.validateEntity(sysAppversion, AddGroup.class);
		sysAppversionService.save(sysAppversion);
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody SysAppversionEntity sysAppversion){
		sysAppversionService.edit(sysAppversion);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody String[] ids){
		sysAppversionService.removeByIds(ids);
		return R.ok();
	}
	
}
